package sc.test.spring.spel;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import sc.common.test.TestUtil;

@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class SpELTest2 {

	public static class TValue {
		String value;

		public String getValue() {
			return value;
		}

		public void setValue(String value) {
			this.value = value;
		}

		@Override
		public String toString() {
			return "Value [value=" + value + "]";
		}
	}

	static final String LOGFMT = "\r\nName:%s\r\nValue:%s";

	public void log(String name, Object value) {
		TestUtil.sp(LOGFMT, name, value);
	}
	
	@Resource
	public TValue vBasic;
	
	@Value("'123'")
	public String vBasic2;

	@Resource
	public TValue vSystemProp;

	@Value("#{ systemProperties['java.home'] }")
	public String vSystemProp2;
	
	@Resource
	public TValue vProp;
	
	
	
	

	@Test
	public void t1() {
		log("vBasic", vBasic);
		log("vBasic2", vBasic2);
		log("vSystemProp", vSystemProp);
		log("vSystemProp2", vSystemProp2);
		log("vProp", vProp);
		
		log("", System.getProperties());
	}
	
	@Autowired
	public void zzzzinner(@Value("#{'set while loading'}")String value) {
		log("defaultValue", value);
	}
	
	@Test
	public void t2() {
		zzzzinner(null);
	}
	
	
}
